﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
using System.Net;
using System.Collections;

public class SendMail
{
    public static void Send(ArrayList Tos, string Title, string Body, bool isAsync, string from)
    {
        MailMessage mailMessage = new MailMessage();
        foreach (string to in Tos)
        {
            mailMessage.To.Add(to);
        }
        mailMessage.From = new System.Net.Mail.MailAddress(from);
        mailMessage.Subject = Title;
        mailMessage.Body = Body;
        mailMessage.IsBodyHtml = false;
        mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
        mailMessage.Priority = System.Net.Mail.MailPriority.Normal;
        string password = "guojia21@";

        if (mailMessage != null)
        {
            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Credentials = new System.Net.NetworkCredential
                (mailMessage.From.Address, password);//设置发件人身份的票据  
            smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtpClient.Host = "smtp." + mailMessage.From.Host;
            smtpClient.Port = 587;//google的smtp端口
            smtpClient.EnableSsl = true;//
            if (isAsync)
            {
                smtpClient.SendAsync(mailMessage, null);
            }
            else
            {
                smtpClient.Send(mailMessage);
            }
        }
    }

    public static void Send(string to, string Title, string Body, bool isAsync, string from)
    {
        ArrayList tos = new ArrayList();
        tos.Add(to);
        Send(tos, Title, Body, isAsync, from);
    }
}

